package com.ruoyi.visitor.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.visitor.domain.VisitorCodeCheck;
import com.ruoyi.visitor.service.IVisitorCodeCheckService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 访客核验记录Controller
 * 
 * @author ruoyi
 * @date 2025-04-12
 */
@Controller
@RequestMapping("/visitor/check")
public class VisitorCodeCheckController extends BaseController
{
    private String prefix = "visitor/check";

    @Autowired
    private IVisitorCodeCheckService visitorCodeCheckService;

    //@RequiresPermissions("system:check:view")
    @GetMapping()
    public String check()
    {
        return prefix + "/check";
    }

    /**
     * 查询访客核验记录列表
     */
    //@RequiresPermissions("system:check:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VisitorCodeCheck visitorCodeCheck)
    {
        startPage();
        List<VisitorCodeCheck> list = visitorCodeCheckService.selectVisitorCodeCheckList(visitorCodeCheck);
        return getDataTable(list);
    }

    /**
     * 导出访客核验记录列表
     */
    //@RequiresPermissions("system:check:export")
    @Log(title = "访客核验记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VisitorCodeCheck visitorCodeCheck)
    {
        List<VisitorCodeCheck> list = visitorCodeCheckService.selectVisitorCodeCheckList(visitorCodeCheck);
        ExcelUtil<VisitorCodeCheck> util = new ExcelUtil<VisitorCodeCheck>(VisitorCodeCheck.class);
        return util.exportExcel(list, "访客核验记录数据");
    }

    /**
     * 新增访客核验记录
     */
    //@RequiresPermissions("system:check:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存访客核验记录
     */
    //@RequiresPermissions("system:check:add")
    @Log(title = "访客核验记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VisitorCodeCheck visitorCodeCheck)
    {
        return toAjax(visitorCodeCheckService.insertVisitorCodeCheck(visitorCodeCheck));
    }

    /**
     * 修改访客核验记录
     */
    //@RequiresPermissions("system:check:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        VisitorCodeCheck visitorCodeCheck = visitorCodeCheckService.selectVisitorCodeCheckById(id);
        mmap.put("visitorCodeCheck", visitorCodeCheck);
        return prefix + "/edit";
    }

    /**
     * 修改保存访客核验记录
     */
    //@RequiresPermissions("system:check:edit")
    @Log(title = "访客核验记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VisitorCodeCheck visitorCodeCheck)
    {
        return toAjax(visitorCodeCheckService.updateVisitorCodeCheck(visitorCodeCheck));
    }

    /**
     * 删除访客核验记录
     */
    //@RequiresPermissions("system:check:remove")
    @Log(title = "访客核验记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(visitorCodeCheckService.deleteVisitorCodeCheckByIds(ids));
    }
}
